var network = require("../../../utils/network.js")
Page({
  data:{
      icons:{
        check: "http://housecleanimags-1255598775.cosbj.myqcloud.com/icon/check.jpg",
        uncheck: "http://housecleanimags-1255598775.cosbj.myqcloud.com/icon/uncheck.png",
        modify: "http://housecleanimags-1255598775.cosbj.myqcloud.com/icon/modify.png",
      }
},
addAddre:function(e){
  	wx.redirectTo({
      url: '../newAddre/index'
    })
  },
toModifyAddre:function(e){
  var index =  e.currentTarget.dataset.modifyid;
  this.setData({
    index:index
  })
  var arrayk = this.data.list
  var modifyaddress = arrayk[index]
  wx.setStorageSync("modifyaddress", modifyaddress)
  wx.navigateTo({
    url: '../modifyAddre/index'
  })
  },
toAppointment:function(e){
  var index = e.currentTarget.dataset.id
  var arrayk = this.data.list
  for(var i = 0 ; i < arrayk.length ; i++){
    arrayk[i].isDefault=false  
  }
  arrayk[index].isDefault = true
  this.setData({
    list:arrayk
  })
   // 上传新的默认地址
  var data ={}
  data.id = index
  data.openid = wx.getStorageSync("openid")
  data.uid = wx.getStorageSync("uid")
  data.token = wx.getStorageSync("token")
  network.postData(
    "https://api.hsb1234.com/userc/v1/mine/addresses/default",
    data,
    function(res){
      var  message = res.data.data.message
      console.log(message)
      wx.navigateBack({
        url: '../../homeClean/hc-appointment/index'
      })
    },
    function (res) { },
  )
  
},
onLoad: function(options) {
  var that = this 
  var data = {}
  data.openid = wx.getStorageSync("openid")
  data.uid = wx.getStorageSync("uid")
  data.token = wx.getStorageSync("token")
  network.getData(
    "https://api.hsb1234.com/userc/v1/mine/addresses",
    data,
    function(res){
      var list = res.data.data
      that.setData({
        list:list
      })
    },
    function(){}
  )
  // var newaddress = wx.getStorageSync('newaddress')
  // var list= that.data.list
  // console.log("这是"+newaddress)
  // if (newaddress){
  //   list.push(newaddress)
  //   this.setData({
  //     list: list
  //   })
  // }
  // var newmodifyaddress = wx.getStorageSync('newmodifyaddress')
  // console.log("这是newmodifyaddress" + newmodifyaddress)
  // if (newmodifyaddress) {
  //   var index = newmodifyaddress.id
  //   list.splice(index, 1, newmodifyaddress)
  //   this.setData({
  //     list: list
  //   })
  // } 
  // var modify = wx.getStorageSync("modify")
  // console.log("这是modify" + modify)
  // if (modify){   
  //   list.splice(modify,1)
  //   for (var i = modify ; i <list.length ;i++){
  //       list[i].id -= 1
  //   }      
  //   this.setData({
  //     list: list
  //   }) 
  //   wx.clearStorageSync('modify')
  //   // 上传新地址列表
  //   // network.postData(list)
  // }
}
})